// pages/keepcar/home.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listInfo: [],
    imgUrls: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.initBanner();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      listInfo: app.globalData.listInfo
    })
    this.initBanner();
  },
  //广告图片初始化
  initBanner: function () {
    var that = this;
    var requrl = app.globalData.hostUrl + 'common/banner';
    var imgbanner = wx.getStorageSync('indexBanner');
    //console.log(imgbanner.length);
    if (!app.expiratTime('indexBanner') || imgbanner.length == 0) {
      wx.request({
        url: requrl,
        data: { 'location': '101' },
        header: {
          'grant-appid': app.globalData.appid
        },
        success: function (res) {
          if (res.statusCode === 200) {
            //console.log(res);
            wx.setStorageSync('indexBanner', res.data.result);
            that.setData({
              imgUrls: res.data.result
            })
          }
        }
      })
    }
    else {
      that.setData({
        imgUrls: imgbanner
      })
    }
  },
  gohome: function () {
    wx.redirectTo({
      url: '../index/index',
    })
  },
  yuy: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../keepcar/mycarsrv',
      })
    }
    else {
      wx.redirectTo({
        url: '../keepcar/adcarsrv',
      })
    }
  },
  orders: function () {
    if (1 == wx.getStorageSync('roleidentity')) {
      wx.redirectTo({
        url: '../keepcar/carsrvmanage',
      })
    }
    else {
      wx.redirectTo({
        url: '../keepcar/hiscarsrv',
      })
    }
  },
  mys: function () {
    wx.redirectTo({
      url: '../myself/myself',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})